/**
 * 
 */
package systole.view.crud.tableModels;

import java.util.List;

import systole.domain.clinicalInformation.Surgery;
import systole.domain.clinicalInformation.SurgeryPatient;

/**
 * @author jmj
 *
 */
public class SurgeriesByPatientTableModel extends SystoleTableModel<SurgeryPatient> {

    private String[] columnNames = {"Cirugía", "Edad"};
    private static final int SURGERY_INDEX = 0;
    private static final int DATE_INDEX = 1;

    /**
     * @param surgeries
     *
     */
    public SurgeriesByPatientTableModel(List<SurgeryPatient> surgeries) {
        super(surgeries);
    }

    /* (non-Javadoc)
     * @see javax.swing.table.TableModel#getColumnClass(int)
     */
    @Override
    public Class<?> getColumnClass(int columnIndex) {
        switch (columnIndex) {
            case SURGERY_INDEX:
                return Surgery.class;
            case DATE_INDEX:
                return Integer.class;
        }
        return null;
    }

    /* (non-Javadoc)
     * @see javax.swing.table.TableModel#getColumnCount()
     */
    @Override
    public int getColumnCount() {
        return this.columnNames.length;
    }

    /* (non-Javadoc)
     * @see javax.swing.table.TableModel#getColumnName(int)
     */
    @Override
    public String getColumnName(int columnIndex) {
        return this.columnNames[columnIndex];
    }

    /* (non-Javadoc)
     * @see javax.swing.table.TableModel#getValueAt(int, int)
     */
    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case SURGERY_INDEX:
                return this.entities.get(rowIndex).getSurgery();
            case DATE_INDEX:
                return this.entities.get(rowIndex).getAgeAtSurgery();
        }
        return null;
    }

    /* (non-Javadoc)
     * @see javax.swing.table.TableModel#setValueAt(java.lang.Object, int, int)
     */
    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case SURGERY_INDEX:
                this.entities.get(rowIndex).setSurgery((Surgery) aValue);
                break;
            case DATE_INDEX:
                this.entities.get(rowIndex).setAgeAtSurgery((Integer) aValue);
                break;
        }
    }
}
